package com.crape.account.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.crape.account.bo.IAccountBO;
import com.crape.account.bo.IDarrenAuditBO;
import com.crape.common.bean.LoginUser;
import com.crape.common.enums.DarrenstatusType;
import com.crape.common.model.Account;
import com.crape.common.model.DarrenAudit;
import com.crape.common.thread.ThreadObjManager;

@Controller
public class DarrenAuditController {

    private IAccountBO     accountBOImpl;

    private IDarrenAuditBO darrenAuditBOImpl;

    @Autowired
    public void setAccountBOImpl(IAccountBO accountBOImpl) {
        this.accountBOImpl = accountBOImpl;
    }

    @Autowired
    public void setDarrenAuditBOImpl(IDarrenAuditBO darrenAuditBOImpl) {
        this.darrenAuditBOImpl = darrenAuditBOImpl;
    }

    @RequestMapping("/darren/auditList.jsp")
    public String auditList(ModelMap modelMap, Integer pageNo) {
        return "/darren/all.html";
    }
    
    @RequestMapping("/darren/reqForm.jsp")
    public String reqForm(ModelMap modelMap, Integer pageNo) {
        LoginUser loginUser = ThreadObjManager.getLoginUser();
        Account account = accountBOImpl.getAccountById(loginUser.getAccountid());
        if(account.getDarrenstatus().equals(DarrenstatusType.pass.getCode())){
            modelMap.put("message", "您目前已经是达人，无需提交申请");
            return "/darren/reqSuccess.html";
        }
        return "/darren/reqForm.html";
    }

    @RequestMapping("/darren/addDarrenReqest.jsp")
    public String addDarrenReqest(ModelMap modelMap, DarrenAudit darrenAudit) {
        LoginUser loginUser = ThreadObjManager.getLoginUser();
        Account account = accountBOImpl.getAccountById(loginUser.getAccountid());
        if(account.getDarrenstatus().equals(DarrenstatusType.pass.getCode())){
            modelMap.put("message", "您目前已经是达人，无需提交申请");
            return "/darren/reqSuccess.html";
        }
        darrenAudit.setAccountid(loginUser.getAccountid());
        darrenAudit.setEmail(loginUser.getEmail());
        darrenAuditBOImpl.addDarrenReqest(darrenAudit);
        modelMap.put("message", "提交申请表单成功");
        return "/darren/reqSuccess.html";
    }

}
